package com.himiotech.core.project.service.impl;

import cn.hutool.core.convert.Convert;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.himiotech.core.project.data.mapper.GenTableColumnMapper;
import com.himiotech.core.project.model.entity.gen.GenTableColumn;
import com.himiotech.core.project.model.metadata.GenTableColumnMetadata;
import com.himiotech.core.project.service.IGenTableColumnService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 业务字段 服务层实现
 *
 * @author ruoyi
 * @author wuwenbin
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class GenTableColumnServiceImpl extends ServiceImpl<GenTableColumnMapper, GenTableColumn> implements IGenTableColumnService {

    @Autowired
    private GenTableColumnMapper genTableColumnMapper;

    /**
     * 查询业务字段列表
     *
     * @param genTableColumn 业务字段信息
     * @return 业务字段集合
     */
    @Override
    public List<GenTableColumn> selectGenTableColumnListByTableId(GenTableColumn genTableColumn) {
        QueryWrapper<GenTableColumn> genTableColumnQueryWrapper = Wrappers.<GenTableColumn>query()
                .eq(GenTableColumnMetadata.TABLE_ID.getColName(), genTableColumn.getTableId())
                .orderByAsc(GenTableColumnMetadata.SORT.getColName());
        return genTableColumnMapper.selectList(genTableColumnQueryWrapper);
    }


    /**
     * 删除业务字段对象
     *
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteGenTableColumnByIds(String ids) {
        return genTableColumnMapper.deleteGenTableColumnByTableIds(Convert.toLongArray(ids.split(",")));
    }
}